<template>
  <div class="mod-role" style="width:100%">
    <el-form
      :inline="true"
      :model="dataForm"
      size="small"
      label-width="130px"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item label="航班号：">
        <el-input v-model="dataForm.FLIGHT_NUM" placeholder="请输入 " clearable></el-input>
      </el-form-item>

      <el-form-item label="航班日期：">
        <el-date-picker
          style="width:200px"
          v-model="dataForm.FLIGHT_DATE"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="始发地：">
        <el-input v-model="dataForm.FLIGHT_FROM" placeholder="请输入" clearable></el-input>
      </el-form-item>
      <el-form-item label="报告制作日期：">
        <el-date-picker
          style="width:200px"
          v-model="dataForm.CREATE_TIME"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="航司代码：">
        <el-input v-model="dataForm.endArea" placeholder="请输入" clearable></el-input>
      </el-form-item>
      <el-form-item label="用户类型：">
        <el-select v-model="dataForm.DEPARTMENT_ID" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="数据类型：">
        <el-select v-model="dataForm.DATA_TYPE" placeholder="请选择">
          <el-option
            v-for="item in options1"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态：">
        <el-checkbox-group v-model="dataForm.FILE_STATUS">
          <el-checkbox label="已完成" name="types"></el-checkbox>
          <el-checkbox label="作废" name="types"></el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item v-if="isAuthBtnS('cha')">
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
       stripe
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
      v-loading="dataListLoading"
      size="small"
      @selection-change="selectionChangeHandle"
      style="width: 100%;"
    >
      <!-- <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column> -->
      <el-table-column
        prop="REPORT_NUM"
        show-overflow-tooltip
        header-align="center"
        align="center"
        min-width="100px"
        sortable
        label="报告编号"
      ></el-table-column>
      <el-table-column
        prop="FLIGHT_NUM"
        show-overflow-tooltip
        header-align="center"
        align="center"
        min-width="100px"
        sortable
        label="航班号"
      ></el-table-column>
      <el-table-column
        prop="FLIGHT_DATE"
        show-overflow-tooltip
        header-align="center"
        align="center"
        sortable
        min-width="100px"
        label="航班日期"
      ></el-table-column>
      <el-table-column
        prop="FLIGHT_FROM"
        show-overflow-tooltip
        header-align="center"
        align="center"
        sortable
        label="始发港"
      ></el-table-column>
      <el-table-column
        prop="FLIGHT_TO"
        show-overflow-tooltip
        header-align="center"
        align="center"
        sortable
        label="目的地"
      ></el-table-column>
      <el-table-column
        prop="DATA_TYPE"
        show-overflow-tooltip
        header-align="center"
        align="center"
        sortable
        min-width="100px"
        label="数据类型"
      ></el-table-column>
      <el-table-column
        prop="FILE_STATUS"
        show-overflow-tooltip
        header-align="center"
        align="center"
        sortable
        label="状态"
      ></el-table-column>
      <el-table-column
        prop="CREATE_DEPARTMENT_NAME"
        show-overflow-tooltip
        header-align="center"
        align="center"
        sortable
        min-width="100px"
        label="用户类型"
      ></el-table-column>
      <el-table-column
        prop="CREATE_USER_NAME"
        show-overflow-tooltip
        header-align="center"
        align="center"
        sortable
        min-width="100px"
        label="操作人员"
      ></el-table-column>
      <el-table-column
        prop="UPDATE_TIME"
        show-overflow-tooltip
        header-align="center"
        align="center"
        sortable
        min-width="100px"
        label="上传时间"
      ></el-table-column>
      <el-table-column
        prop="MEMO"
        show-overflow-tooltip
        header-align="center"
        align="center"
        sortable
        min-width="100px"
        label="备注"
      ></el-table-column>

      <!-- <el-table-column prop="roleName" header-align="center" align="center" label="备注"></el-table-column> -->

      <el-table-column fixed="right" header-align="center" align="left" width="220" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="addOrUpdateHandle(scope.row.FILE_URL)">查看</el-button>
          <el-button
            type="danger"
            v-if="isAuthBtnS('del')&&scope.row.IS_DEL=='0'"
            size="mini"
            @click="changeStatus(scope.row)"
          >作废</el-button>
          <el-button
            type="success"
            v-if="isAuthBtnS('del')&&scope.row.IS_DEL=='1'"
            size="mini"
            @click="changeStatus(scope.row)"
          >恢复</el-button>
          <el-button size="mini" @click="downLoadPdf(scope.row.ID,scope.row.FILE_URL)">下载</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>

    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from "./abroadadd";
export default {
  data() {
    return {
      qxlist: {},
      dataForm: {
        FLIGHT_NUM: "",
        FLIGHT_DATE: "",
        FLIGHT_FROM: "",
        CREATE_TIME: "",
        DEPARTMENT_ID: "",
        FILE_STATUS: [],
        IS_DEL: [],
        DATA_TYPE: "",
        value1: "",
        type: ""
      },
      options: [
        { value: "", label: "所有" },
        { value: "3", label: "单证" },
        { value: "4", label: "库区" },
        { value: "5", label: "查看" }
      ],
      options1: [
        { value: "", label: "所有" },
        { value: "ICFR", label: "IFCR" },
        { value: "理货报告", label: "理货报告" },
        { value: "进港航班货物登记表", label: "进港航班货物登记表" },
        {
          value: "Container Administration",
          label: "Container Administration"
        },
        {
          value: "Quaruantine Feedback Report",
          label: "Quaruantine Feedback Report"
        },
        {
          value: "进港温控药品操作流程检查单",
          label: "进港温控药品操作流程检查单"
        },
        { value: "DMG REPORT", label: "DMG REPORT" },
        { value: "邮路单", label: "邮路单" },
        { value: "VAL进港检查单", label: "VAL进港检查单" },
        { value: "其他文件", label: "其他文件" }
      ],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    };
  },
  components: { AddOrUpdate },
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    isAuthBtnS(data) {
      return this.qxlist && this.qxlist[data] && this.qxlist[data] == "1"
        ? true
        : false;
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/air/basic/list"),
        method: "POST",
        data: this.$http.adornData({
          page: this.pageIndex,
          showCount: this.pageSize,
          IS_DEL: this.dataForm.IS_DEL.join(","),
          FLIGHT_NUM: this.dataForm.FLIGHT_NUM,
          FILE_STATUS: this.dataForm.FILE_STATUS.join(","),
          FLIGHT_DATE: this.dataForm.FLIGHT_DATE,
          DATA_TYPE: this.dataForm.DATA_TYPE,
          CREATE_TIME: this.dataForm.CREATE_TIME,
          DEPARTMENT_ID: this.dataForm.DEPARTMENT_ID,
          FLIGHT_FROM: this.dataForm.FLIGHT_FROM
        })
      }).then(({ data }) => {
        if (data) {
          this.qxlist = Object.assign({}, this.qxList, data.QX);
          this.dataList = data.list;
          this.totalPage = data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      if (!id || id.length == 0) {
        this.$message.error("没有文件");
        return false;
      }
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id);
      });
    },
    downLoadPdf(id, url) {
      if (!url) {
        this.$message.error("没有文件");
        return false;
      }
      this.$http({
        url: this.$http.adornUrl("/air/pdf/uploadpdf"),
        method: "post",
        data: this.$http.adornData({
          url:
            window.location.origin +
            "/aper/air/pdf/air?ID=" +
            id +
            "&OPER=OPER",
          fileUrl: id + ".pdf"
        })
      }).then(({ data }) => {
        if (data && data.result == 1) {
          window.open(data.url);
        } else {
          this.$message.error(data.message);
        }
      });
    },
    // 删除
    changeStatus(item) {
      this.$prompt("请输入原因", "提示", {
        confirmButtonText: "确定",
        inputPattern: /\S/,
        inputErrorMessage: "请输入原因",
        inputType: "textarea",
        cancelButtonText: "取消"
      })
        .then(({ value }) => {
          this.$http({
            url: this.$http.adornUrl("/air/file_DEL"),
            data: this.$http.adornData({
              ID: item.ID,
              IS_DEL: item.IS_DEL == "1" ? "0" : "1",
              REPORT_ID: item.REPORT_ID,
              MEMO: value
            }),
            method: "post"
          }).then(({ data }) => {
            if (data && data.result == "1") {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.getDataList();
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        })
        .catch(() => {});
    },
    zuofei(item) {
      this.$prompt("请输入原因", "提示", {
        confirmButtonText: "确定",
        inputPattern: /\S/,
        inputErrorMessage: "请输入作废原因",
        inputType: "textarea",
        cancelButtonText: "取消"
      })
        .then(({ value }) => {
          this.$http({
            url: this.$http.adornUrl("/air/file_DEL"),
            data: this.$http.adornData({
              ID: item.ID,
              IS_DEL: item.IS_DEL == "1" ? "0" : "1",
              REPORT_ID: item.REPORT_ID,
              MEMO: value
            }),
            method: "post"
          }).then(({ data }) => {
            if (data && data.result == "1") {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.getDataList();
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        })
        .catch(() => {});
    }
  }
};
</script>

<style lang="scss">
.mod-role {
  .el-checkbox {
    margin-right: 10px;
  }
  .el-checkbox:last-child {
    margin-right: 0;
  }
  .el-checkbox + .el-checkbox {
    margin: 0;
    margin-right: 10px;
  }
}
</style>
